package conf

import (
	"github.com/gookit/config/v2"
	"github.com/gookit/config/v2/yaml"
)

type _http struct {
	Host  string `config:host`
	Port  uint   `config:"port"`
	Debug bool   `config:"debug"`
}

type _mysql struct {
	Host     string `config:"host"`
	Port     uint   `config:"port"`
	User     string `config:"user"`
	Password string `config:"password"`
	Database string `config:"database"`
	Charset  string `config:"utf8mb4"`
}

type _jwt struct {
	Secret      string `config:secret`
	IdentityKey string `config:identity_key`
}

type _conf struct {
	Http    _http  `config:"http"`
	MySQL   _mysql `config:"dsn"`
	Jwt     _jwt   `config:jwt`
	Workdir string `config:"workdir"`
}

var Conf _conf

func init() {
	config.AddDriver(yaml.Driver)

	err := config.LoadFiles("conf.yml")
	if err != nil {
		panic(err)
	}

	err = config.Decode(&Conf)
	if err != nil {
		panic(err)
	}
}
